#include "CollisionSubject.h"

#include <algorithm>

#include "Conversions.h"
#include "LevelChangeListener.h"
#include "Logger.h"

CollisionSubject::~CollisionSubject()
{
}

CollisionSubject& CollisionSubject::operator=(const CollisionSubject& rhs)
{
    if(this == &rhs) return *this;

    listeners = rhs.listeners;

    return *this;
}

void CollisionSubject::registerListener(CollisionListener* listener, CollisionType collisionType)
{
    // Get the vector of listeners for this particular type of collision.
    // If the vector hasn't been created yet, it will be default-constructed by the map.
    listener_vec& typeListeners = listeners[collisionType];
    listener_vec_it it = std::find(typeListeners.begin(), typeListeners.end(), listener);
    if(it != typeListeners.end())
    {
        LOG("Warning: collision listener at " + toString(*it) +
            " already registered with collision subject at " + toString(this) + '.');
    }
    else
    {
        typeListeners.push_back(listener);
    }
}

void CollisionSubject::unregisterListener(CollisionListener* listener)
{
}

void CollisionSubject::notifyListenersOfCollision(EntityPtr entity1, EntityPtr entity2,
CollisionType collisionType)
{
    /*for(listener_it it = listeners.begin(); it != listeners.end(); ++it)
    {
        (*it)->onFinished();
    }*/
}